package ui;

import dao.AttendanceDAO;
import javax.swing.*;
import java.awt.*;
import java.sql.Date;
import java.util.Calendar;

public class SignInFrame extends JFrame {
    public SignInFrame() {
        setTitle("学生签到");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);

        JLabel nameLabel = new JLabel("学生姓名:");
        JTextField nameField = new JTextField(15);
        JLabel courseLabel = new JLabel("课程名称:");
        JTextField courseField = new JTextField(15);
        JButton signBtn = new JButton("签到");

        JPanel panel = new JPanel(new GridLayout(3, 2));
        panel.add(nameLabel); panel.add(nameField);
        panel.add(courseLabel); panel.add(courseField);
        panel.add(new JLabel()); panel.add(signBtn);

        signBtn.addActionListener(e -> {
            String name = nameField.getText();
            String course = courseField.getText();
            Date date = new Date(Calendar.getInstance().getTimeInMillis());
            boolean result = new AttendanceDAO().signIn(name, course, date);
            JOptionPane.showMessageDialog(this, result ? "签到成功" : "签到失败");
        });

        add(panel);
        setVisible(true);
    }
}
